/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author QUYET
 */
public class Model {

    protected Connection getConnection() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
        Connection conn = null;
        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        Class.forName(driverName).newInstance();
        String url = "jdbc:sqlserver://localhost:1433;databasename = AutoAncillaries";
        String user = "sa";
        String pass = "1234567";
        conn = DriverManager.getConnection(url, user, pass);
        return conn;

    }

    protected void closeObject(Object obj) throws SQLException {
        if (obj instanceof Connection) {
            ((Connection) obj).close();
        }
        if (obj instanceof ResultSet) {
            ((ResultSet) obj).close();
        }
        if (obj instanceof PreparedStatement) {
            ((PreparedStatement) obj).close();
        }
        if (obj instanceof Statement) {
            ((Statement) obj).close();
        }
    }
}
